﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WeChat.Common;
using WeChat.Common2;
using WeChat.HyfPay.Hyflib;

namespace WeChat.HyfPay
{
    public partial class SyntheticPay : System.Web.UI.Page
    {
        public static string wxJsApiParam { get; set; } //H5调起JS API参数
        public string openid;     
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void btn1_Click(object sender, EventArgs e)
        {
            #region //打印请求头
            var coll = Request.Headers;
            String[] arr1 = coll.AllKeys;
            JObject jo = new JObject();
            for (int i = 0; i < arr1.Length; i++)
            {
                String[] arr2 = coll.GetValues(arr1[i]);
                for (int j = 0; j < arr2.Length; j++)
                {
                    jo.Add(arr1[i], Server.HtmlEncode(arr2[j]));
                }
            }
            ApplicationLog.Write("二维码集成页面获取请求headers：" + jo.ToString());
            #endregion

            //判断请求头，是微信app还是支付宝app提交的请求
            string agent = Request.Headers["User-Agent"].ToString();
            string url = "";
            string order_No = Request.QueryString["order_No"].ToString();
            string amount = Request["selVal"].ToString();
            string equipmentID = Request.QueryString["equipmentID"].ToString();
            string goodsName = Request.QueryString["goodsName"].ToString();
            //如果请求头判断为微信app请求则调用微信二维码下单接口
            if (agent.IndexOf("MicroMessenger") > -1)
            {
                wxJsApiParam = HyfPayApi.getResult("014", order_No, goodsName, amount, equipmentID,"");
                ApplicationLog.Write("wxJsApiParam：" + wxJsApiParam);
                //url = "http://" + Config.domainName + "/JsSDK/WxPay/WxPay.aspx?openid=" + openid + "&total_fee=" + amount + "&attach=" + equipmentID;
            }
            //如果请求头判断为支付宝app请求则调用支付宝二维码下单接口
            else if (agent.IndexOf("AlipayClient") > -1)
            {
                 url = HyfPayApi.getResult("009", order_No, goodsName, amount, equipmentID,"");
            }
                Response.Redirect(url);
        }
    }
}